#include "Human.h"

Human::Human(btDiscreteDynamicsWorld* pWorld,
             btCylinderShape* pHumanCollisionShape,
             Ogre::SceneManager* pSceneManager,
             OpenSteer::Vec3 position) :
  Character::Character(pWorld, pHumanCollisionShape, pSceneManager,
                       position, HUMANMESH) {

  // AnimationState
  Ogre::AnimationState* humanAnimation =
    _pEntity->getAnimationState("Walk");
  humanAnimation->setEnabled(true);
  humanAnimation->setLoop(true);
  humanAnimation->setTimePosition(0.0);

  // OpenSteer ---------------------------------------------------------

  // Bullet vehicle
  setMaxForce(100);
  setMaxSpeed(3);
}

void
Human::update(const float currentTime, const float elapsedTime) {

  // Orientar respecto a su vector dirección
  Ogre::Vector3 ogreDirection(forward().x, forward().y, forward().z);
  _pNode->setDirection(-ogreDirection);

  // Animar el humano
  _pEntity->getAnimationState("Walk")->addTime(elapsedTime);

  // Eliminar fuerzas
  _pRigidBody->clearForces();

  // Eliminar velocidad
  _pRigidBody->setLinearVelocity(btVector3(0, 0, 0));
}

void
Human::translate(btVector3 translation) {

  _pRigidBody->activate();
  _pRigidBody->translate(translation);
}
